<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Datei: language.class.php
 *
 * Set and reset text domain after recording the current
 * one. This ist important for plugins etc.
 *
 * @author Norbert Gebert
 * @copyright Norbert Gebert 25.09.2011
 * @license GPL3
 *
 * @version 0.5b
 * @package Admin
 * @subpackage global
 */
class language
{

	private $_domainStack = array();

	//$_td_stack = array(); // text domains stack

	/**
	 * Set the Standard Text domain
	 */
	function __construct($textDomain, $path, $language, $charset = 'UTF-8')
	{
		setlocale(LC_ALL, $language);
		// Path to Language-Files
		bindtextdomain($textDomain, $path);
		// setting Domain
		textdomain($textDomain);
		bind_textdomain_codeset($textDomain, $charset);
	}

	/**
	 * Sets a new text domain.
	 * @param	string	the new text domain to set
	 */
	public static function setTextDomain($td)
	{
		$oldTd = textdomain(NULL);

		if ($oldTd)
		{
			if (!strcmp($oldTd, $td))
			{
				array_push($this->_domainStack, false);
			}
			else
			{
				array_push($this->_domainStack, $oldTd);
			}
		}

		textdomain($td);
	}

	/**
	 * Restore the text domain active .
	 */
	public static function restTextDomain()
	{
		$oldTd = array_pop($this->_domainStack, $oldTd);

		if ($oldTd)
			textdomain($oldTd);
	}

}